/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import POJO.POJO_DatVe;
import POJO.POJO_KhachHang;
import POJO.POJO_VeTau;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Master
 */
public class DAO_DatVe {
    DataProvider data;
    
    public List<POJO_DatVe> findAll() throws SQLException {
        data = new DataProvider();
        data.Open();
        
        String query = "SELECT * FROM dat_ve";
        
        List<POJO_DatVe> lst = new ArrayList<>();
        ResultSet rs = data.ExecuteQuery(query);
        
        while (rs.next()) {
            POJO_DatVe dv = new POJO_DatVe();
            dv.setMAVE(rs.getString("MAVE"));
            dv.setCMND(rs.getString("CMND"));
                
            lst.add(dv); 
        }
        
        return lst;
    } 
    
    public int xoaDatVe(POJO_DatVe dv) {
        data = new DataProvider();
        data.Open();
        
        String sql = String.format("DELETE FROM dat_ve WHERE MaVe='%s' and CMND = '%s'",
            dv.getMAVE(),
            dv.getCMND());
            
            
        return data.ExeCuteUpdate(sql);
    }
    
    public int themDatVe(POJO_DatVe dv) {
        data = new DataProvider();
        data.Open();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String sql = String.format("Insert into dat_ve values ('%s','%s')",
                dv.getMAVE(),
                dv.getCMND());
                    
            
        return data.ExeCuteUpdate(sql);
    } 
}
